package com.chengxiaoxiao.ai_demo.exception;

import com.chengxiaoxiao.ai_demo.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理类
 *
 * @Description:
 * @Author Cheng Xiaoxiao
 * @Date: 2025/3/13 09:12
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {
    /**
     * 处理系统逻辑产生的异常
     *
     * @param e 异常对象
     * @return 异常信息JSON
     */
    @ExceptionHandler(value = GlobalException.class)
    public Result<String> handleGlobalException(GlobalException e) {
        log.error(e.getMessage(), e);
        return Result.error(e.getCm());
    }
}
